package com.huilai.platform.country_platform.controller;

import com.huilai.platform.country_platform.model.AttractionsBuilding;
import com.huilai.platform.country_platform.model.AttractionsWaterscape;
import com.huilai.platform.country_platform.service.AttractionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 作者：洪霓
 * 日期：2023/2/16
 * 注释：
 */
@Controller
@RequestMapping("/attractions")
public class AttractionsController {

    @Autowired
    private AttractionsService attractionsService;

    @RequestMapping("/buildingListUI")
    public String buildingListUI(Model model, @ModelAttribute("searchName") String searchName, @PageableDefault(size = 10) Pageable pageable){
        Page<AttractionsBuilding> page = attractionsService.buildingListUI(searchName,pageable);
        List<AttractionsWaterscape> top10Waterscape = attractionsService.getTopWaterscape();
        model.addAttribute("page", page);
        model.addAttribute("top10Waterscape", top10Waterscape);
        return "attractions/attractions-building";
    }

    @RequestMapping("/buildingDetailsUI")
    public String buildingDetailsUI(Model model, @ModelAttribute("id")Integer id, @PageableDefault(size = 10)Pageable pageable){
        AttractionsBuilding attractionsBuilding = attractionsService.findBuildingsById(id);
        List<AttractionsWaterscape> top10Waterscape = attractionsService.getTopWaterscape();
        model.addAttribute("attractionsBuilding",attractionsBuilding);
        model.addAttribute("top10Waterscape",top10Waterscape);
        return "attractions/attractions-building-details";
    }

    @RequestMapping("/waterscapeListUI")
    public String waterscapeListUI(Model model, @ModelAttribute("searchName")String searchName, @PageableDefault(size = 10)Pageable pageable){
        Page<AttractionsWaterscape> page = attractionsService.waterscapeListUI(searchName,pageable);
        List<AttractionsBuilding> top10Building = attractionsService.getTopBuilding();
        model.addAttribute("page", page);
        model.addAttribute("top10Building", top10Building);
        return "attractions/attractions-waterscape";
    }

    @RequestMapping("/waterscapeDetailsUI")
    public String waterscapeDetailsUI(Model model, @ModelAttribute("id")Integer id, @PageableDefault(size = 10)Pageable pageable){
        AttractionsWaterscape attractionsWaterscape = attractionsService.findWaterscapesById(id);
        List<AttractionsBuilding> top10Building = attractionsService.getTopBuilding();
        model.addAttribute("attractionsWaterscape",attractionsWaterscape);
        model.addAttribute("top10Building",top10Building);
        return "attractions/attractions-waterscape-details";
    }

}
